<?php

class DatabaseObject_NotificationSettings extends DatabaseObject {
    
    public function __construct($db) {
        parent::__construct($db, 'notification_settings', 'id');
        
        $this->add('idUser');
        $this->add('new_pm');
        $this->add('new_com');
        $this->add('new_req');
        $this->add('acc_req');
        $this->add('new_order');
    }
    
    private static function _GetBaseQuery($db, $options) {
        // инициализация настроек
        $defaults = array();

        foreach ($defaults as $k => $v) {
            $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v;
        }

        // создание запроса на получение
        $select = $db->select();
        $select->from(array('ns' => 'notification_settings'), array());

        return $select;
    }
    
    public static function UserNotificationSettingsExists($db, $user_id) {
        $query = sprintf('select count(*) as num from notification_settings where idUser = %d', $user_id);

        $result = $db->fetchOne($query);

        return $result > 0;
    }
}
